﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Betop.Lib.Core.Base;
using Betop.Lib.Web;


namespace Betop.Lib.Core.Company
{
    public class CompanyBO : CommonOperate<CompanyInfo>
    {
        private CompanyDAL _company;
        public CompanyBO()
        {
            _company = new CompanyDAL();
        }

        protected override BaseDAL DAL
        {
            get 
            {
                return _company;
            }
        }

        public CompanyInfo GetInfoByUrl(string url)
        {
            CompanyInfo info = _company.GetInfoByUrl(url);
            return info;
        }

        /// <summary>
        /// 根据当前的域名来获取实体
        /// </summary>
        /// <returns></returns>
        public CompanyInfo GetInfo()
        {
            string url = System.Web.HttpContext.Current.Request.Url.Host.Replace("www", "").Trim('.');
            return GetInfoByUrl(url);
        }

        /// <summary>
        /// 初始化一个公司
        /// </summary>
        /// <param name="domain"></param>
        public CompanyInfo InitInfo(string domain)
        {
            CompanyInfo info = new CompanyInfo();
            info.Name = "某某公司";
            info.Email = "";
            info.SiteDomain = domain;

            base.Save(info);

            return info;
        }

        public override List<CompanyInfo> GetList(PagerSortSetting pagerSetting)
        {
            string condition = _company.GetPagerCondition((string)pagerSetting.Input);
            List<CompanyInfo> list = base.GetList(pagerSetting, condition, "%" + pagerSetting.Input + "%");
            return list;
        }

        //public override void Delete(IEnumerable<int> ids)
        //{

        //    MenuBO menu = new MenuBO();
        //    //menu.DeleteByCompany(ids);


        //    base.Delete(ids);
        //}

        public CompanyInfo GetInfoByLoginName(string companyLoginName)
        {
            if (string.IsNullOrEmpty(companyLoginName))
            {
                return null;
            }
            CompanyInfo info = _company.GetInfoByLoginName(companyLoginName);
            return info;
        }
    }
}
